<?php

//文件上传并生成缩略图类
include_once (root . '/library/fileupload.php');
include_once (root . '/library/graphicsextend.php');

class FileUploadThumb extends FileUpload {

    public function upload($fields = NULL, $params = array()) {
        if (!$params) {
            $params = $_REQUEST;
        }
        $ret = parent::upload($fields);
        if ($ret) {
            $this->thumb($params);
        }
        return $ret;
    }

    public function thumb($params) {
        $thumb = new GraphicsExtend();
        if (!isset($params['cutwidth'])) {
            $params['cutwidth'] = '200';
        }
        if (!isset($params['mode'])) {
            $params['mode'] = 'w';
        }
        if (!isset($params['ext'])) {
            $params['ext'] = 'l';
        }
        foreach ($this->filelist as $key => $value) {
            if ($value->succeed && preg_match('/.+(jpg|png|gif)$/', $value->ext)) {
                $thumb->Zoom($value->path, $params['mode'], $params['cutwidth'], $params['ext']);
            }
        }
    }

}

?>
